package com.chessbit {
package model {

import _root_.net.liftweb.common._
import _root_.net.liftweb.util._
import _root_.net.liftweb.sitemap._
import _root_.net.liftweb.sitemap.Loc._
import _root_.net.liftweb.mongodb._
import _root_.net.liftweb.mongodb.record.{MongoRecord, MongoId, MongoMetaRecord}
import _root_.net.liftweb.mongodb.record.field.ObjectIdPk
import _root_.net.liftweb.record.field._
import net.liftweb.http.S
import _root_.net.liftweb.mongodb.record.field._

case class Move(san: String, comment: String) extends JsonObject[Move] {
  def meta = Move
}
object Move extends JsonObjectMeta[Move]


class Game private() extends MongoRecord[Game] with ObjectIdPk[Game] {
  def meta = Game

  object title extends StringField(this, 20)
  object result extends StringField(this, 10)
  object white extends StringField(this, 50)
  object black extends StringField(this, 50)
  object ECO extends StringField(this, 5)
  object round extends StringField(this, 50)
  object site extends StringField(this, 50)
  object date extends StringField(this, 10)
  object eventDate extends StringField(this, 10)
  object whiteElo extends StringField(this, 4)
  object blackElo extends StringField(this, 4)
  object plyCount extends IntField(this)
  
  object moves extends MongoJsonObjectListField(this, Move)

}

object Game extends Game with MongoMetaRecord[Game] {
  override def collectionName = "games"
    
  //val entry = Menu.param[Game]("game", S ? "game.view", (id: String) => Game.find(id), (g: Game) => g.id.is ) / "game" >> Hidden  
  
  //def calcHref(bp: Game) = entry.toLoc.calcHref(bp)
}

}
}
